//
//  HNSH_SignGoodsExChangeRecordViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/4/23.
//

#import "HNSH_SignGoodsExChangeRecordViewController.h"

#import "HNSH_SignGoodsExChangeRecordCell.h"

@interface HNSH_SignGoodsExChangeRecordViewController ()

/* dataArray */
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

static NSString *HNSH_SignGoodsExChangeRecordCellID = @"HNSH_SignGoodsExChangeRecordCellID";

@implementation HNSH_SignGoodsExChangeRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self showNavTitle:@"兑换记录" showLeftItem:YES];
    
    [self configTableView];
}

- (void)refreshData:(NSInteger)page {
    [HNSH_UserNetServer requestSignGoodsExchangeRecordWithPage:page success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            if (page == 1) {
                [self.dataArray removeAllObjects];
            }
            NSArray * records = responseObject.resultset[@"list"];
            NSArray * array = [NSArray yy_modelArrayWithClass:HNSH_SignGoodsExChangeRecordModel.class json:records];
            [self.dataArray addObjectsFromArray:array];
            [self endRefresh:array.count>=10];
            [self.tableView reloadData];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

- (void)configTableView {
    self.tableView.backgroundColor = [UIColor appBGColor];
    [self.tableView registerClass:[HNSH_SignGoodsExChangeRecordCell class] forCellReuseIdentifier:HNSH_SignGoodsExChangeRecordCellID];
    self.tableView.rowHeight = 120;
    self.tableView.estimatedRowHeight = 120;
    
    //添加刷新
    [self setupRefresh:self.tableView option:ST_RefreshDefault];
    //添加空页面
    [self setupEmpty:self.tableView image:[UIImage imageNamed:@"empty_list_data"] title:@""];
}

#pragma mark - delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 14.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HNSH_SignGoodsExChangeRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:HNSH_SignGoodsExChangeRecordCellID];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
